insatllEvent = function (obj) {
  var event = {
    clientList: {},
    listen: function (key, fn) {
      if (!this.clientList[key]) {
        this.clientList[key] = [];
      }
      this.clientList[key].push(fn);
    },
    dispatch: function () {
      var args = Array.prototype.shift.call(arguments);
      if (!this.clientList[args] || this.clientList[args].length === 0) {
        return false;
      }
      for (let i = 0, fn; (fn = this.clientList[args][i++]); ) {
        // 参数为发布时候参数
        fn.apply(this, arguments);
      }
    },
    remove: function(key,fn) {
        if(!this.clientList[key]){
            return false
        }
        if(!fn){
          this.clientList[key].length = 0
        }else {
            for (let i = 0; i <  this.clientList[key].length; i++) {
                let _fn =  this.clientList[key][i]
                if(fn == _fn){
                    this.clientList[key].splice(i,1)
                }
            }
        }
    }
  };
  for (const key in event) {
    obj[key] = event[key]
  }
};

var saleOffices = {}

insatllEvent(saleOffices)

saleOffices.listen("小于80平米", function (price) {
    console.log("订阅者1",price);
})
saleOffices.listen("小于100平米", function (price) {
    console.log("订阅者2",price);
})
saleOffices.listen("小于80平米", function (price) {
    console.log("订阅者3",price);
})
saleOffices.listen("小于80平米", function (price) {
    console.log("订阅者4",price);
})

saleOffices.dispatch("小于80平米", 20000)